package com.fengpt.mysqlback.web;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.time.LocalDateTime;

//@Configuration      //1.主要用于标记配置类，兼备Component的效果。
//@EnableScheduling   // 2.开启定时任务
public class SaticScheduleTask {
    //3.添加定时任务
    //@Scheduled(cron = "0 46 23 * * ?")
    //或直接指定时间间隔，例如：5秒
    //@Scheduled(fixedRate=5000)
    private void configureTasks() {
        String[] cmds = new String[] { "/bin/sh", "-c",
                "/usr/local/apps/halo/docker_mysql.sh" };
        System.out.println("start***********");
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(cmds, null, null);
            InputStreamReader ir = new InputStreamReader(process
                    .getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
            String line;
            process.waitFor();
            while ((line = input.readLine()) != null) {
                System.out.println(line);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            System.out.println("error***********"+e.getMessage());
            e.printStackTrace();
        }finally{
            process.destroy();
        }
        System.out.println("end***********");




    }


}